﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using Model;
using MsDAL;

namespace ServiceHelper
{
    public class PopManager
    {
        PopDal dal = new PopDal();

        private static PopManager _getInitialize;
        /// <summary>
        /// 得到PersonManager类的实体对象
        /// </summary>
        public static PopManager GetInitialize
        {
            get
            {
                if (_getInitialize == null)
                    _getInitialize = new PopManager();
                return _getInitialize;
            }
        }

        public DataTable GetPopData(string tableName, string fields, string otherFieldName, string order, string where, string otherWhere, int rownum)
        {
            return dal.GetPopData(tableName, fields, otherFieldName, order, where, otherWhere, rownum);
        }

        public PopItem GetPopItem(string code)
        {
            DataTable dt = dal.GetPopItem(code);
            if (dt == null || 0 == dt.Rows.Count) return null;

            return PopManager.GetPopItemByDataRow(dt.Rows[0]);
        }


        public static PopItem GetPopItemByDataRow(DataRow dr)
        {
            PopItem model = new PopItem(); //实例化PopItem

            if (!(dr["popno"] is System.DBNull))
                model.Popno = (string)dr["popno"];
            if (!(dr["ptable"] is System.DBNull))
                model.Table = (string)dr["ptable"];
            if (!(dr["pkey"] is System.DBNull))
                model.Key = (string)dr["pkey"];
            if (!(dr["fields"] is System.DBNull))
                model.ShowFields = (string)dr["fields"];
            if (!(dr["pagesize"] is System.DBNull))
                model.PageSize = (int)dr["pagesize"];
            if (!(dr["orderfid"] is System.DBNull))
                model.OrderFid = (string)dr["orderfid"];
            if (!(dr["strwhere"] is System.DBNull))
                model.StrWhere = (string)dr["strwhere"];
            if (!(dr["keyref"] is System.DBNull))
                model.KeyRef = (string)dr["keyref"];
            if (!(dr["reffield"] is System.DBNull))
                model.RefField = (string)dr["reffield"];
            if (!(dr["issavekey"] is System.DBNull))
                model.IsSaveKey = (string)dr["issavekey"];
            if (!(dr["description"] is System.DBNull))
                model.Desc = (string)dr["description"];
            if (!(dr["width"] is System.DBNull))
                model.Width = (int)dr["width"];
            if (!(dr["height"] is System.DBNull))
                model.Height = (int)dr["height"];

            return model;
        }
    }
}
